package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 统计类型枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum StatisticsType implements BaseEnum {
    WEEKLY("weekly", "周统计"),
    MONTHLY("monthly", "月统计"),
    QUARTERLY("quarterly", "季度统计"),
    SEMESTER("semester", "学期统计"),
    YEARLY("yearly", "年统计"),
    DAILY("daily", "日统计"),
    REAL_TIME("real_time", "实时统计"),
    HISTORICAL("historical", "历史统计"),
    PREDICTIVE("predictive", "预测统计"),
    COMPARATIVE("comparative", "对比统计"),
    CUMULATIVE("cumulative", "累计统计"),
    AVERAGE("average", "平均统计"),
    TREND("trend", "趋势统计"),
    PEAK("peak", "峰值统计"),
    DISTRIBUTION("distribution", "分布统计"),
    SUMMARY("summary", "汇总统计"),
    DETAILED("detailed", "详细统计"),
    AGGREGATE("aggregate", "聚合统计"),
    INDIVIDUAL("individual", "个人统计"),
    GROUP("group", "群体统计"),
    DEPARTMENT("department", "部门统计"),
    ORGANIZATION("organization", "组织统计"),
    CUSTOM("custom", "自定义统计"),
    SYSTEM("system", "系统统计"),
    MANUAL("manual", "手动统计"),
    AUTOMATIC("automatic", "自动统计"),
    SCHEDULED("scheduled", "计划统计"),
    ON_DEMAND("on_demand", "按需统计");

    private final String code;
    private final String description;

    StatisticsType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static StatisticsType fromCode(String code) {
        for (StatisticsType type : StatisticsType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown statistics type code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static StatisticsType fromDescription(String description) {
        for (StatisticsType type : StatisticsType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown statistics type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}